#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices, int fee) {
        vector<int> dp0(2, 0);
        dp0[1] = -prices[0];
        vector<int>dp1(2, 0);
        for (int i = 1; i < prices.size(); ++i) {
            dp1[0] = max(dp0[0], dp0[1] + prices[i] - fee);
            dp1[1] = max(dp0[1], dp0[0] - prices[i]);
            swap(dp0, dp1);
        }
        return dp0[0];
    }
};
//
//int main() {
//    vector<int> prices = { 1,3,7,5,10,3 };
//    Solution sol;
//    sol.maxProfit(prices, 3);
//}